


import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:get/get.dart';
class WebViewPage extends StatefulWidget {
  const WebViewPage({super.key});

  @override
  State<WebViewPage> createState() => _WebViewPageState();
}

class _WebViewPageState extends State<WebViewPage> with SingleTickerProviderStateMixin {
  late WebViewController controller;
  late AnimationController animationController = AnimationController(vsync: this);
  String title = "";
  @override
  void initState() {

    final params = Get.arguments as Map<String, dynamic>;
    final url = params["url"] as String;
    title = params["title"] as String;

    controller = WebViewController()
      ..loadRequest(Uri.parse(url))
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
            animationController.value = (progress / 100).toDouble();
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onWebResourceError: (WebResourceError error) {},
          onNavigationRequest: (NavigationRequest request) {
            if (request.url.startsWith('https://www.youtube.com/')) {
              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
        ),
      );


    super.initState();
  }
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(title:  Text(title)),
      body: Stack(children: [
        WebViewWidget(controller: controller),
        // AnimatedBuilder(animation: animationController, builder: (context, child){
        //   if (animationController.value == 1.0) {
        //     return Container();
        //   }else {
        //     return ClipRRect(
        //       borderRadius: BorderRadius.circular(1.5),
        //       child: LinearProgressIndicator(
        //         minHeight: 3,
        //         backgroundColor: Colors.grey,
        //         valueColor: const AlwaysStoppedAnimation(Colors.red),
        //         value: animationController.value,
        //       ),
        //     );
        //   }
        //
        // }),
      ]),
    );
  }
}
